import json
import time
import traceback
import requests
from squirrel_bakend.config.basic import SEND_URL


def save(data):
    header = {"Content-Type": "application/json"}
    # try:
    #     result = requests.request("POST", f"{SEND_URL}", data=json.dumps(data), headers=header)
    #     if result.status_code != 200:
    #         time.sleep(3)
    #         logger.info(f"数据推送失败，准备重试")
    #         result = requests.request("POST", f"{SEND_URL}", data=json.dumps(data), headers=header)
    #         if result.status_code == 200:
    #             logger.info(f"数据推送成功")
    #         else:
    #             logger.info(f"推送数据失败，结果为{result.text}")
    #     else:
    #         logger.info(f"数据推送成功，结果为{result.text}")
    # except Exception:
    #     logger.info(f"推送数据时出现异常，准备重试！{traceback.format_exc()}")
    #     result = requests.request("POST", f"{SEND_URL}", data=json.dumps(data), headers=header)
    #     if result.status_code != 200:
    #         logger.info(f"推送数据失败，结果为{result.text}")
    #     else:
    #         logger.info(f"数据推送成功，结果为{result.text}")
    # finally:
    #     return result.text
